import axios from "axios"
import { resResolve, resReject, reqResolve, reqReject } from './interceptors'

/**
 * 创建axios对象
 *
 * @param {Object} options 配置参数
 * @returns {Object} axios对象
 */
export function createAxios(options = {}) {
  const defaultOptions = {
    baseURL: import.meta.env.VITE_APP_BASE_API,
    timeout: 1000 * 30
  }
  const server = axios.create({
    ...defaultOptions,
    ...options
  })
  server.interceptors.request.use(reqResolve, reqReject)
  server.interceptors.response.use(resResolve, resReject)
  return server
}

export const defAxios = createAxios()
